﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication6.Models;
using MvcApplication6.DAL;

namespace MvcApplication6.BIZ
{
    public class MenuL2BIZ
    {
        MenuL2DAL DAL = new MenuL2DAL();

        ProductBIZ BIZ_product = new ProductBIZ();

        //---------------------Menu_l2Search-----------------------------
        public List<MenuL2Model> Menu_l2Select()
        {
            try
            {
                List<MenuL2Model> lst = new List<MenuL2Model>();
                lst = DAL.Menu_l2Select();

                return lst;
            }
            catch (Exception)
            {
                throw;
            }
        }

        //---------------------Menu_l2SearchById-----------------------------
        public MenuL2Model Menu_l2SearchById(int id)
        {
            try
            {
                MenuL2Model lst = new MenuL2Model();
                lst = DAL.Menu_l2SearchById(id);

                return lst;
            }
            catch (Exception)
            {
                throw;
            }
        }

        //---------------------Menu_l2SearchById_l1-----------------------------
        public List<MenuL2Model> Menu_l2SearchById_l1(int id_l1)
        {
            try
            {
                List<MenuL2Model> lst = new List<MenuL2Model>();
                lst = DAL.Menu_l2SearchById_l1(id_l1);

                return lst;
            }
            catch (Exception)
            {
                throw;
            }
        }

        //---------------------Menu_l2Insert-----------------------------
        public int Menu_l2Insert(int id_l1, string name, int position)
        {
            try
            {
                int i = DAL.Menu_l2Insert(id_l1, name, position);

                return i;
            }
            catch (Exception)
            {
                throw;
            }
        }

        //---------------------Menu_l2Update-----------------------------
        public int Menu_l2Update(int id, int id_l1, string name, int position)
        {
            try
            {
                int i = DAL.Menu_l2Update(id, id_l1, name, position);

                return i;
            }
            catch (Exception)
            {
                throw;
            }
        }

        //---------------------Menu_l2Delete-----------------------------
        public int Menu_l2Delete(int id)
        {
            try
            {
                int i = DAL.Menu_l2Delete(id);

                return i;
            }
            catch (Exception)
            {
                throw;
            }
        }

        //----------------------Delete menu L2 voi dk co san pham
        public int DeleteMenu_L2WhenHadProduct(int idmenu)
        {
            List<ProductModel> lst_model = new List<ProductModel>();

            lst_model = BIZ_product.ProductSearchById_l2(idmenu);
            int so_luong = lst_model.Count();

            if (so_luong == 0)
            {
                int i = Menu_l2Delete(idmenu);
                
                return i;
            }

            return -1;
        }
    }
}